#include <cstdio>

using namespace std;

#define MAX 14

int k, n;
static int a[MAX];

int minM(int k) {
	n = k << 1;
	int m=k+1;
	bool b = true;
	while (true) {
		int s = 0, j;
		for (j=n; j>k; j--) {
			s = (s+m-1)%j;
			if (s < k) break;
		}
		if (j == k) break;;
		b ? m++ : m=m+k;
		b=!b;
	}
	return m;
}

int main (void) {
	while (true) {
		scanf("%d", &k);
		if (k == 0) break;
		if (!a[k]) {
			a[k] = minM(k);
		}
		printf("%d\n", a[k]);
	}
}
